// packageAPI/pages/device/calendar/calendar.js
Page({
  data: {
    schema: [{
      label:'标题',
      prop:'title',
      type:'text'
    },{
      label:'开始时间',
      prop:'startTime',
      type:'number'
    },{
      label:'结束时间',
      prop:'endTime',
      type:'number'
    },{
      label:'是否全天事件',
      prop:'allDay',
      type:'switch'
    },{
      label:'事件说明',
      prop:'description',
      type:'text'
    },{
      label:'事件位置',
      prop:'location',
      type:'text'
    },{
      label:'是否提醒',
      prop:'alarm',
      type:'switch'
    },{
      label:'提醒提前量',
      prop:'alarmOffset',
      type:'number'
    }],
    formData: {
      title:'标题',
      startTime:new Date().getTime(),
      endTime:new Date().getTime(),
      allDay:false,
      description:'',
      location:'',
      alarm:true,
      alarmOffset:0
    },
    title: '',
    result: '',
    zh:'',
    apiType: '',
    remark: '',
    webUrl: '',
    apiName: '',
  },

  onLoad(options) {
    this.setData({
      apiType: options.zh,
      title: options.title,
      zh: options.zh,
      remark: options.remark,
      webUrl: options.webUrl
    })
    let time = new Date().getTime()
  },
  getFormData(e){
    this.setData({
      formData:e.detail.formData
    })
  },
  addPhoneCalendar(){
    let data = this.data.formData
    wx.addPhoneCalendar({
      title:data.title,
      startTime:data.startTime,
      endTime:data.endTime,
      description:data.description,
      location:data.location,
      allDay:data.allDay,
      alarm:data.alarm,
      alarmOffset:data.alarmOffset,
      complete:(res)=>{
        this.setData({
          result:res,
          apiName:'wx.addPhoneCalendar'
        })
      }
    })
  }
})